<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 12/9/18
 * Time: 9:58 PM
 */

class Utils
{
    public static function isFromRemoteClient($data)
    {
        return isset($data['flag']) && $data['flag'] === 'r';
    }

    public static function subscribeValid($data)
    {
        //币库 + 交易所
        if (!isset($data['topic']) || !in_array($data['topic'], ['coin', 'exchange'])) return false;
        if ($data['topic'] === 'exchange' && (!isset($data['name']) || !$data['name'])) return false;
        return true;
    }

    public static function getGroupName($data)
    {
        if (isset($data['name']) && $data['name'] && $data['name'] !== 'null') return $data['topic'].'_'.$data['name'];
        return $data['topic'];
    }

    public static function isValidData($data)
    {
        return isset($data['data']) && !empty($data['data']);
    }
}